package com.gxa.logistics.controller;


import com.gxa.logistics.common.base.R;
import com.gxa.logistics.domain.dto.MaterialDTO;
import com.gxa.logistics.domain.dto.TransferrecordDTO;
import com.gxa.logistics.service.impl.MaterialServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "库存管理-物料管理")
@RequestMapping("/material")
public class MaterialController {
    @Resource
    private MaterialServiceImpl materialService;

    @PostMapping("/insert") //插入数据
    public Map<String, Object> insert(@RequestBody MaterialDTO materialDTO) {
        return materialService.insert(materialDTO);
    }
    @PostMapping("/delete") //删除数据
    public R delete(@RequestParam Integer material_id) {
        materialService.delete(material_id);
        return R.success();
    }
    @PostMapping("/update") //修改
    public Map<String, Object> update(@RequestBody MaterialDTO materialDTO) {
        return materialService.update(materialDTO);
    }

    @ApiOperation(value = "物料名字查询")
    @GetMapping("/selectMaterialByName") //按物料名字查询
    public R selectMaterialByName(@RequestParam String material_name) {
        List<MaterialDTO> selectMaterialByName = materialService.selectMaterialByName(material_name);
        return R.success(selectMaterialByName);
    }

    @GetMapping("/selectMaterialByWarehouseName") //按仓库名字查询
    public Map<String, Object> selectMaterialByWarehouseName(@RequestParam String warehouse_name) {
        return materialService.selectMaterialByWarehouseName(warehouse_name);
    }


    @GetMapping("/selectMaterial") //浏览与分页
    public Map<String, Object> selectMaterial(@RequestParam int page, @RequestParam int limit) {
        return materialService.selectMaterial(page, limit);
    }

}
